using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using facade.Singleton;
using util.AttributeExtension;
using util.EnumExtion;

namespace openapi
{
    /// <summary>
    /// 单例模式
    /// </summary>
    [ApiController]
    [Route("[controller]")]
    //[ApiExplorerSettings(GroupName = "Singleton")]
    //[ApiGroupName("Singleton")]
    [ApiGroupName(ApiGroupNameEnum.Singleton)]
    public class SingletonController : ControllerBase
    {
        /// <summary>
        /// 饿汉模式
        /// </summary>
        /// <returns></returns>
        [HttpGet("Hungry")]
        public string Hungry()
        {
            Singleton s1 = Singleton.GetSingleton();
            Singleton s2 = Singleton.GetSingleton();
            if (s1 == s2)
            {
                return "true";
            }
            return "false";
        }

        /// <summary>
        /// 懒汉模式
        /// </summary>
        /// <returns></returns>
        [HttpGet("Lazy")]
        public string Lazy()
        {
            Singleton2 s1 = Singleton2.GetSingleton2();
            Singleton2 s2 = Singleton2.GetSingleton2();
            if (s1 == s2)
            {
                return "true";
            }
            return "false";
        }
    }
}